<div class="page-header">
    <h1>
        Form Tambah Produk
        <small>
            <i class="icon-double-angle-right"></i>
            Penambahan Produk
        </small>
    </h1>
</div>

<?php
if ($this->errmsg) {
    ?>
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-remove"></i>
            Error
        </strong>

        <?php echo $this->errmsg; ?>
        <br />
    </div>
    <?php
}

if ($this->msg) {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-ok"></i>
        </strong>

        <?php echo $this->msg; ?>
        <br />
    </div>
    <?php
}

if (!$this->msg && !$this->errmsg) {
    ?>

    <div class="row">
        <div class="col-xs-11">
            <form id="formAdd" class="form-horizontal" role="form" action="" method="post">
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="suplier_id"> Parent Produk </label>

                        <div class="col-sm-9">
                        <select class="col-xs-10 col-sm-5 chosen-select" id="parent_product_id" name="parent_product_id" data-placeholder="Pilih parent produk...">
                            <option value=""> Pilih parent produk...</option>
                            <?php
                                foreach($this->parents as $parent){
                                        echo '<option value="' . $parent['product_id'] . '">' . $parent['product_code']. ' - ' .$parent['product_name'] . '</option>';
                                }

                            ?>
                        </select>
			</div>

                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="code"> Kode Produk </label>

                    <div class="col-sm-9">
                        <input type="text" id="product_code" name="product_code" placeholder="Kode Produk" class="col-xs-10 col-sm-5" value="<?php if (isset( $this->data['product_code'] )) { echo $this->data['product_code'];} ?>" required />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="product_name"> Nama Produk </label>

                    <div class="col-sm-9">
                        <input type="text" id="product_name" name="product_name" placeholder="Nama Produk" class="col-xs-10 col-sm-5" value="<?php if (isset( $this->data['product_name'] )) { echo $this->data['product_name'];} ?>" required />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="product_desc"> Deskripsi Produk </label>

                    <div class="col-sm-9">
                        <input type="text" id="product_desc" name="product_desc" placeholder="Deskripsi Produk" class="col-xs-10 col-sm-5" value="<?php if (isset( $this->data['product_desc'] )) { echo $this->data['product_desc'];} ?>" required />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="product_owner_id"> Owner </label>

                        <div class="col-sm-9">
                        <select class="col-xs-10 col-sm-5 chosen-select" id="product_owner_id" name="product_owner_id" data-placeholder="Pilih Suplier..." required>
                            <option value=""> Pilih Owner...</option>
                            <?php
                                foreach($this->owners as $owner){
                                        echo '<option value="' . $owner['product_owner_id'] . '">' . $owner['product_owner_name']. '</option>';
                                }

                            ?>
                        </select>
			</div>

                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="suplier_id"> Suplier </label>
					
                        <div class="col-sm-9">
                        <select class="col-xs-10 col-sm-5 chosen-select" id="suplier_id" name="suplier_id" data-placeholder="Pilih Suplier..." required>
                            <option value=""> Pilih Suplier...</option>
                            <?php
                                foreach($this->supliers as $suplier){
                                        echo '<option value="' . $suplier['suplier_id'] . '">' . $suplier['suplier_name']. ' - ' .$suplier['suplier_address'] . '</option>';
                                }
                           
                            ?>
                        </select>
			</div>
			
                </div>
                
            <div class="clearfix form-actions">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-success" type="submit">
                        <i class="icon-ok bigger-110"></i>
                        Submit
                    </button>

                    &nbsp; &nbsp; &nbsp;
                    <button class="btn" type="reset">
                        <i class="icon-undo bigger-110"></i>
                        Reset
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);

    var satrtDate = $('#start_dat').datepicker({
      format: 'yyyy-mm-dd'
    }).on('changeDate', function(ev) {
      //if (ev.date.valueOf() > endDate.date.valueOf()) {
        var newDate = new Date(ev.date)
        newDate.setDate(newDate.getDate() + 1);
        endDate.setValue(newDate);
      //}
      satrtDate.hide();
      $('#end_dat')[0].focus();
    }).data('datepicker');

    var endDate = $('#end_dat').datepicker({
      onRender: function(date) {
        return date.valueOf() <= satrtDate.date.valueOf() ? 'disabled' : '';
      }, format: 'yyyy-mm-dd'
    }).on('changeDate', function(ev) {
      endDate.hide();
    }).data('datepicker');

    function validateNumber(evt) {

        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
      }
</script>
<?php } ?>